package com.pan.games.play;

import java.util.concurrent.locks.LockSupport;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2021/3/3
 */
public class PrintABC1 {

    public static void main(String[] args) {
        Thread main = Thread.currentThread();
        Thread a = new Thread(()->{
            while(true) {
                LockSupport.park();
                System.out.println("a");
                LockSupport.unpark(main);
            }
        },"a");

        Thread b = new Thread(()->{
            while(true) {
                LockSupport.park();
                System.out.println("b");
                LockSupport.unpark(main);
            }
        },"b");

        Thread c = new Thread(()->{
            while(true){
                LockSupport.park();
                System.out.println("c");
                LockSupport.unpark(main);
            }
        },"c");
        a.start();
        b.start();
        c.start();
        Thread[] tt = new Thread[]{a,b,c};
        for(int i = 0;i<30;i++){
            int j = i%3;
            Thread temp = tt[j];
            LockSupport.unpark(temp);
            LockSupport.park();
        }

    }
}
